package ces.frame.module.homePage.action;

import java.io.File;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
import org.apache.poi.hssf.record.formula.functions.Int;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.omg.CORBA.PUBLIC_MEMBER;

import ces.frame.module.homePage.bo.HomePageBO;
import ces.frame.module.tree.action.TreeAction;
import ces.frame.module.tree.bo.TreeBo;
import ces.frame.util.CommonUtil;
import ces.frame.util.anyPlace.APCommon;
import ces.frame.util.anyPlace.APWrite;
import ces.frame.util.anyPlace.file.download.DownloadFile;
import ces.frame.util.coral.tag.table.Page;
import ces.frame.util.internal.ICommon;
import ces.sdk.system.bean.UserInfo;
import ces.workflow.wapi.org.User;

public class HomePageAction extends DispatchAction{
	
	public HomePageBO homePageBO;
	
	public TreeBo treeBo;

	
	
	public TreeBo getTreeBo() {
		return treeBo;
	}

	public void setTreeBo(TreeBo treeBo) {
		this.treeBo = treeBo;
	}

	public HomePageBO getHomePageBO() {
		return homePageBO;
	}

	public void setHomePageBO(HomePageBO homePageBO) {
		this.homePageBO = homePageBO;
	}
	
	/**
	 * 获取首页通知公告与制度规范列表
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @date 2015-7-28 下午06:32:17
	 * @author 
	 */
	public void getNoticeAndStandardAction(ActionMapping mapping,ActionForm form, 
		HttpServletRequest request,HttpServletResponse response){
		try {
			String state = APCommon.objToStr(request.getParameter("state"));
			String rownum = APCommon.objToStr(request.getParameter("rownum"));
			List<Map<String,Object>> list = this.homePageBO.getNotice(state,"1060",rownum);
			Map<String,List<Map<String,Object>>> map = new HashMap<String, List<Map<String,Object>>>();
			if(list != null && !list.isEmpty()){
				map.put("Notice", list);
			}
			//根据张局意见，制度规范模块去掉
			/*list = this.homePageBO.getNotice(state,"1030",rownum);
			if(list != null && !list.isEmpty()){
				map.put("Standard", list);
			}*/
			map.put("Standard", null);
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			APWrite.outPrintRespose("0", response);
			e.printStackTrace();
		}
	}
	/**
	 * 获取首页 图片中心与常用下载数据
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @date 2015-7-29 下午04:51:23
	 * @author 
	 */
	public void getDownloadAndImg(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String state = APCommon.objToStr(request.getParameter("state"));
			String rownum = APCommon.objToStr(request.getParameter("rownum"));
			String code = APCommon.objToStr(request.getParameter("code"));
			List<Map<String,Object>> list = this.homePageBO.getNotice(state,"1130",rownum);
			Map<String,List<Map<String,Object>>> map = new HashMap<String, List<Map<String,Object>>>();
			if(list != null && !list.isEmpty()){//根据张局意见，图片中心模块去掉
				map.put("Download", list);
			}
			//根据张局意见，图片中心模块去掉
			/*list = this.homePageBO.getImagesCenter(code, rownum);
			if(list != null && !list.isEmpty()){
				map.put("Images", list);
			}*/
			map.put("Images", null);
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 下载通知公告、常用下载、制度规范 附件
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @date 2015-7-29 下午05:44:54
	 * @author 
	 */
	public void getFiel(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String id = APCommon.objToStr(request.getParameter("id"));
			List<Map<String,Object>> list = this.homePageBO.getFile(id);
			if(list != null && !list.isEmpty()){
				Map<String,Object> map = list.get(0);
				String root = APCommon.getPropertyValueTwo("USER_DATA_HOME_DIR")+"web";
				String fileName = APCommon.objToStr(map.get("FILE_NAME"));
				String filePath = APCommon.objToStr(map.get("FILE_PATH"));
				DownloadFile df = new DownloadFile();
				df.setCode("UTF-8");
				df.setDownloadName(fileName);
				df.setFilePath(root+File.separator+filePath+File.separator+fileName);
				df.download(response);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	/**
	 * 下载档案表附件
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @date 2015-7-29 下午05:45:24
	 * @author 
	 */
	public void getAtthFiel(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String id = APCommon.objToStr(request.getParameter("id"));
			String code = APCommon.objToStr(request.getParameter("code"));
			String fileType = APCommon.objToStr(request.getParameter("fileType"));
			List<Map<String,Object>> list = this.homePageBO.getAtthFile(code, id, fileType);
			if(list != null && !list.isEmpty()){
				Map<String,Object> map = list.get(0);
				String root = APCommon.getPropertyValueTwo("UPLOAD_PATH")+APCommon.getPropertyValueTwo("AFFIX_DIR");
				String atthName = APCommon.objToStr(map.get("ATTH_NAME"));
				String atthPath = APCommon.objToStr(map.get("ATTH_PATH"));
				String atthType = APCommon.objToStr(map.get("ATTH_TYPE"));
				
				DownloadFile df = new DownloadFile();
				df.setCode("UTF-8");
				df.setDownloadName(atthName+atthType);
				df.setFilePath(root+atthPath+atthName+atthType);
				df.download(response);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 查看全宗
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @date 2015-7-29 下午07:19:14
	 * @author 
	 */
	public ActionForward seeQzData(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		String forward = APCommon.objToStr(request.getParameter("forward"));
		try {
			Page page = new Page();
			String pageSize = APCommon.isNotNull(request.getParameter("pageSize"))?request.getParameter("pageSize"):page.getPageSize()+"";
			String pageNo = APCommon.isNotNull(request.getParameter("pageNo"))?request.getParameter("pageNo"):page.getPageNo()+"";
			page.setPageSize(Integer.valueOf(pageSize));
			page.setPageNo(Integer.valueOf(pageNo));
			page = this.homePageBO.seeQzData(page);
			request.setAttribute("page",page);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapping.findForward(forward);
	}
	
	/**
	 * 查看所有列表
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @date 2015-7-29 下午07:19:14
	 * @author 
	 */
	public ActionForward seeAllData(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		String forward = APCommon.objToStr(request.getParameter("forward"));
		try {
			String state = APCommon.objToStr(request.getParameter("state"));
			String menuId = APCommon.objToStr(request.getParameter("menuId"));
			Page page = new Page();
			String pageSize = APCommon.isNotNull(request.getParameter("pageSize"))?request.getParameter("pageSize"):page.getPageSize()+"";
			String pageNo = APCommon.isNotNull(request.getParameter("pageNo"))?request.getParameter("pageNo"):page.getPageNo()+"";
			page.setPageSize(Integer.valueOf(pageSize));
			page.setPageNo(Integer.valueOf(pageNo));
			page = this.homePageBO.seeAllData(page, state, menuId);
			request.setAttribute("page",page);
			request.setAttribute("menuName",ICommon.getMenuName(menuId));
			request.setAttribute("state",state);
			request.setAttribute("menuId",menuId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapping.findForward(forward);
	}
	
	/**
	 * 查看图片中心所有列表
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @date 2015-7-29 下午07:19:14
	 * @author 
	 */
	public ActionForward seeAllImgData(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		String forward = APCommon.objToStr(request.getParameter("forward"));
		try {
			String code = APCommon.objToStr(request.getParameter("code"));
			String currentId = APCommon.objToStr(request.getParameter("currentId"));
			String type = APCommon.objToStr(request.getParameter("type"));
			String openType = APCommon.objToStr(request.getParameter("openType"));
			Page page = new Page();
			String pageSize = APCommon.isNotNull(request.getParameter("pageSize"))?request.getParameter("pageSize"):page.getPageSize()+"";
			String pageNo = APCommon.isNotNull(request.getParameter("pageNo"))?request.getParameter("pageNo"):page.getPageNo()+"";
			page.setPageSize(Integer.valueOf(pageSize));
			page.setPageNo(Integer.valueOf(pageNo));
			page = this.homePageBO.seeAllImgData(page, code);
			List<String[]> list = page.getContent();
			String ids = "";
			for(int i=0; i<list.size(); i++){
				if(APCommon.isNull(currentId) && type.equals("next")){
					currentId = list.get(i)[0];
				}
				if(APCommon.isNull(currentId) && type.equals("up")){
					currentId = list.get(list.size()-1)[0];
				}
				ids += list.get(i)[0]+",";
				
			}
			ids = "".equals(ids)?"":ids.substring(0, ids.length()-1);
			request.setAttribute("ids",ids);
			request.setAttribute("openType",openType);
			request.setAttribute("currentId",currentId);
			request.setAttribute("page",page);
			request.setAttribute("code",code);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapping.findForward(forward);
	}
	
	/**
	 * 查看详细
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @date 2015-7-29 下午07:21:14
	 * @author 
	 */
	public ActionForward seeDetailed(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		String forward = APCommon.objToStr(request.getParameter("forward"));
		String id = APCommon.objToStr(request.getParameter("id"));
		try {
			List<Map<String,Object>> list = this.homePageBO.seeDetailed(id);
			
			Map<String,Object> map = null;
			if(list != null && !list.isEmpty()){
				/*map = list.get(0);
				String path = APCommon.getPropertyValueTwo("WEB_ISSUE_PATH")+APCommon.objToStr(map.get("CONTENT_PATH"));
				map.put("CONTENT", ICommon.readHtml(path));*/
				map = list.get(0);
				for(int a =0;a<list.size();a++){
					map.put("CONTENT"+a, ICommon.readHtml(APCommon.getPropertyValueTwo("WEB_ISSUE_PATH")+APCommon.objToStr(list.get(a).get("CONTENT_PATH"))));
					map.put("FILEID"+a, APCommon.objToStr(list.get(a).get("FILEID")));
					map.put("FILE_NAME"+a, APCommon.objToStr(list.get(a).get("FILE_NAME")));
				}
			}
			map.put("size", list.size());
			request.setAttribute("map",map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mapping.findForward(forward);
	}
	
	/**
	 * 查看全宗详细
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @date 2015-7-29 下午07:21:14
	 * @author 
	 */
	public ActionForward seeQzDetailed(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		String forward = APCommon.objToStr(request.getParameter("forward"));
		String id = APCommon.objToStr(request.getParameter("id"));
		try {
			List<Map<String,Object>> list = this.homePageBO.seeQzDetailed(id);
			List<Map<String,Object>> listAtth = this.homePageBO.seeQzAtthDetailed(id, "");//全宗附件信息
			Map<String,Object> map = null;
			if(list!=null&&list.size()>0){
				map = list.get(0);
			}
			request.setAttribute("map",map);
			request.setAttribute("listAtth",listAtth);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mapping.findForward(forward);
	}
	
	/**
	 * 获取待办、已办、办结列表
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @date 2015-7-29 下午07:19:14
	 * @author 
	 */
	public ActionForward getWorkTasks(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		String forward = APCommon.objToStr(request.getParameter("forward"));
		try {
			Page page = new Page();
			String status = APCommon.objToStr(request.getParameter("status"));
			String tabId = APCommon.objToStr(request.getParameter("tabId"));
			String pageSize = APCommon.isNotNull(request.getParameter("pageSize"))?request.getParameter("pageSize"):page.getPageSize()+"";
			String pageNo = APCommon.isNotNull(request.getParameter("pageNo"))?request.getParameter("pageNo"):page.getPageNo()+"";
			UserInfo user=(UserInfo)request.getSession().getAttribute("user");
			int countNum = 0;
			page.setPageSize(Integer.valueOf(pageSize));
			page.setPageNo(Integer.valueOf(pageNo));
			String where = "";
			if("daiban".equals(tabId)){
				//where = "and t.activity_id='approveagain' and t.status !=14 and t.owner_id = '" + user.getUserID() + "'";
				where = "and t.activity_id not in('decidefile','start') and t.status !=14 and t.owner_id = '" + user.getUserID() + "'";
			}else if("yiban".equals(tabId)){
				//where = "and t.activity_id='approveagain' and t.status =14 and t.owner_id = '" + user.getUserID() + "'";
				where = "and t.activity_id not in('decidefile','start') and t.status =14 and t.owner_id = '" + user.getUserID() + "'";
			}else if("banjie".equals(tabId)){
				where = "and t.activity_id='decidefile' and t.status =14"+
					" and exists(select 1 from t_mh_writings a where a.ztid = m.id and a.IS_CATALOG='0' and a.COLLECT_NAME='" + user.getUserID() + "')";
			}
			page = this.homePageBO.getWorkTasks(page, user.getUserID()+"", status, where);
			List list = page.getContent();
			
			request.setAttribute("page",page);
			request.setAttribute("status", status);
			request.setAttribute("tabId", tabId);
			request.setAttribute("userName",user.getUserName());
			request.setAttribute("userId",user.getUserID());
			//request.setAttribute("countNum",this.homePageBO.getWorkTaskCount(user.getUserID()+"")+"");
			request.setAttribute("countNum",countNum+"");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapping.findForward(forward);
	}
	
	/**
	 * 首页近10年项目验证情况图表
	 * @param code
	 * @param year
	 * @return
	 * @date 2015-8-5 下午03:15:23
	 * @author 
	 */
	public void getXmysCharts(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String code = APCommon.objToStr(request.getParameter("code"));
			String year = APCommon.objToStr(request.getParameter("year"));
			if(APCommon.isNull(year)){
				year = APCommon.dateToStr(new Date(), "yyyy");
			}
			//Map<String,Object> map = this.homePageBO.getXmysCharts(code, year);
			Map<String,Object> map = this.homePageBO.getExborrowData();
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
    /*
     * 温度统计(按年)
	*/
	public void getTemperatureCharts(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String year = APCommon.objToStr(request.getParameter("year")==null?"":request.getParameter("year"));
			if(APCommon.isNull(year)){
				year = APCommon.dateToStr(new Date(), "yyyy");
			}
			Map<String,Object> map = this.homePageBO.getTemperature(year);
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
    /*
     * 湿度统计(按年)
	*/
	public void getHumidityCharts(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String year = APCommon.objToStr(request.getParameter("year")==null?"":request.getParameter("year"));
			if(APCommon.isNull(year)){
				year = APCommon.dateToStr(new Date(), "yyyy");
			}
			Map<String,Object> map = this.homePageBO.getHumidity(year);
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
	
	
	 /*
     * 温度不合格统计(按年)
	*/
	public void getTemperatureChartsBhg(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String year = APCommon.objToStr(request.getParameter("year")==null?"":request.getParameter("year"));
			if(APCommon.isNull(year)){
				year = APCommon.dateToStr(new Date(), "yyyy");
			}
			Map<String,Object> map = this.homePageBO.getTemperatureBhg(year);
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
    /*
     * 湿度不合格统计(按年)
	*/
	public void getHumidityChartsBhg(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String year = APCommon.objToStr(request.getParameter("year")==null?"":request.getParameter("year"));
			if(APCommon.isNull(year)){
				year = APCommon.dateToStr(new Date(), "yyyy");
			}
			Map<String,Object> map = this.homePageBO.getHumidityBhg(year);
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
	
	
	
	 /*
     * 温度统计(按月)
	*/
	public void getTemperatureByMonthCharts(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String month = APCommon.objToStr(request.getParameter("yearMonth"));
			if(APCommon.isNull(month)){
				month = APCommon.dateToStr(new Date(), "yyyy");
			}
			Map<String,Object> map = this.homePageBO.getTemperature2(month);
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
    /*
     * 湿度统计(按月)
	*/
	public void getHumidityByMonthCharts(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String month = APCommon.objToStr(request.getParameter("yearMonth"));
			if(APCommon.isNull(month)){
				month = APCommon.dateToStr(new Date(), "yyyy");
			}
			Map<String,Object> map = this.homePageBO.getHumidity2(month);
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
	
	
	
	 /*
     * 温度不合格统计(按月)
	*/
	public void getTemperatureByMonthChartsBhg(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String month = APCommon.objToStr(request.getParameter("yearMonth"));
			if(APCommon.isNull(month)){
				month = APCommon.dateToStr(new Date(), "yyyy");
			}
			Map<String,Object> map = this.homePageBO.getTemperatureBhg2(month);
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
    /*
     * 湿度不合格统计(按月)
	*/
	public void getHumidityByMonthChartsBhg(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String month = APCommon.objToStr(request.getParameter("yearMonth"));
			if(APCommon.isNull(month)){
				month = APCommon.dateToStr(new Date(), "yyyy");
			}
			Map<String,Object> map = this.homePageBO.getHumidityBhg2(month);
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
	
	/**
	 * 登陆后档案利用情况
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 */
	public void getArUseCharts(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			String parmStr = APCommon.objToStr(request.getParameter("parmStr"));
			String num = APCommon.objToStr(request.getParameter("num"));
			Map parmMap = new HashMap();
			parmMap.put("num", num);
			parmMap.put("arType", parmStr);
			List<Object[]> list = this.homePageBO.getArUseCharts(parmMap);
			APWrite.listOutJson(list, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
	
	/**
	 * 库房档案上架情况
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 */
	public void getStorageArCharts(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			//String parmStr = APCommon.objToStr(request.getParameter("parmStr"));
			Map parmMap = new HashMap();
			//parmMap.put("arType", parmStr);
			List<Object[]> list = this.homePageBO.getStorageArCharts(parmMap);
			
			APWrite.listOutJson(list, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
	
	/**
	 * 获取首页档案库存数量
	 * @param code
	 * @param year
	 * @return
	 * @date 2015-8-5 下午03:15:23
	 * @author 
	 */
	public void getDaqkCharts(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response){
		/*int afterYear = Integer.valueOf(APCommon.objToStr(request.getParameter("afterYear")));
		String year = APCommon.objToStr(request.getParameter("year"));*/
		String parmStr = APCommon.objToStr(request.getParameter("parmStr"));
		try {
			Map parmMap = new HashMap();
			parmMap.put("line", parmStr.split("!-!")[0]);
			parmMap.put("arType", parmStr.split("!-!")[1]);
			
			//List<Object[]> list = this.homePageBO.getDaqkCharts(year,afterYear);
			List<Object[]> list = this.homePageBO.getArDataCharts(parmMap);
			APWrite.listOutJson(list, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
	
	/**
	 * 获取登录后利用数据统计报表
	 * @param code
	 * @param year
	 * @return
	 * @date 2015-8-5 下午03:15:23
	 * @author 
	 */
	public void getLysCharts(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response){
		int beforMonth = Integer.valueOf(APCommon.objToStr(request.getParameter("beforMonth")));
		String year = APCommon.objToStr(request.getParameter("year"));
		try {
			Map<String, Object> map = this.homePageBO.getLysCharts(year,beforMonth);
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
	/**
	 * 照片档案查看详细档案数据
	 * @param code
	 * @param year
	 * @return
	 * @date 2015-8-5 下午03:15:23
	 * @author 
	 */
	public void getArchivesDetailed(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response){
		String code = APCommon.objToStr(request.getParameter("code"));
		String id = APCommon.objToStr(request.getParameter("id"));
		try {
			Map<String, Object> map = this.homePageBO.getArchivesDetailed(code,id);
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
	
	/**
	 * 列表自定义行数
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @date 2015-10-26 上午10:18:08
	 * @author 
	 */
	public void setListShowRowAction(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response){
		String row = APCommon.objToStr(request.getParameter("row"));
		UserInfo user=(UserInfo)request.getSession().getAttribute("user");
		try {
			int i = this.homePageBO.setListShowRow(row, user.getUserID()+"", user.getUserName());
			APWrite.outPrintRespose(i+"", response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
	
	/**20180524zhaoqun
	 * 利用目的统计
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 */
	public void getLiYongCharts(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		try {
			Map<String,Object> map = this.homePageBO.getLiyongData();
			
			//利用目的数据转换成图表数据：利用目的:1经济建设2落实政策3社会保障4编史修志5工作查考6学术研究7宣传教育8其他
			String[] str = (String[]) map.get("series");
			
			String[] echartJjjs = new String[str.length];
			String[] echartLssh = new String[str.length];
			String[] echartShbz = new String[str.length];
			String[] echartBsxz = new String[str.length];
			String[] echartGzkc = new String[str.length];
			String[] echartXsyj = new String[str.length];
			String[] echartXcjx = new String[str.length];
			String[] echartQt = new String[str.length];
			
			

			
			for(int i =0; i<str.length;i++) {
				
				//1经济建设
				count(str[i], echartJjjs, "1",i);
				//2落实政策
				count(str[i], echartLssh, "2",i);
				//3社会保障
				count(str[i], echartShbz, "3",i);
				//4编史修志
				count(str[i], echartBsxz, "4",i);
				//5工作查考
				count(str[i], echartGzkc, "5",i);
				//6学术研究
				count(str[i], echartXsyj, "6",i);
				//7宣传教育
				count(str[i], echartXcjx, "7",i);
				//8其他
				count(str[i], echartQt, "8",i);
			}
			
			map.put("echartJjjs", echartJjjs);
			map.put("echartLssh", echartLssh);
			map.put("echartShbz", echartShbz);
			map.put("echartBsxz", echartBsxz);
			map.put("echartGzkc", echartGzkc);
			map.put("echartXsyj", echartXsyj);
			map.put("echartXcjx", echartXcjx);
			map.put("echartQt", echartQt);
			
			APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}

	/**
	 * 统计字符出现的数量
	 * @param @param str 字符串
	 * @param @param echart 存储字符出现的数量
	 * @param @param chars  字符
	 * @param @param i 下标
	 * @date 2018年5月25日
	 * @author zhaoqun
	 */
	private void count(String str, String[] echart, String chars, int i) {
		int begin;
		int after;
		String string = new String();
		if(str.contains(chars)) {
			begin = str.length();
			string = str.replaceAll(chars,"");
			after = string.length();
			echart[i] = begin-after+"";
		}else {
			echart[i] = "0";
		}
	}
	
	
	/**
	 * 档案类型统计
	 * @param @param mapping
	 * @param @param form
	 * @param @param request
	 * @param @param response
	 * @date 2018年5月28日 
	 * @author zhaoqun
	 */
	
	
	public void getTypeCharts(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		
		try {
		Map<String,Object> map = new HashMap<String,Object>();
		
		String mediaRootCode=ResourceBundle.getBundle("config").getString("MEDIA_ROOT_CODE").toString();
		
		List archiveType = treeBo.getArchiveTypeOutM("0000","",mediaRootCode);
		
		String[] type = new String[archiveType.size()];//存储类型
		Integer[] typeTwo= new Integer[archiveType.size()];//存储二级类型
		
		for(int i=0;i<archiveType.size();i++) {
			String[] row=(String[])archiveType.get(i);
			type[i] = row[1];
			
			//List num = treeBo.getArchiveTypeOutM(row[0],"",mediaRootCode);
			//typeTwo[i] = num.size();
			
		}
		
		System.out.println(Arrays.toString(type));
		//System.out.println(Arrays.toString(typeTwo));
		
		map.put("type", type);
		//map.put("typeTwo", typeTwo);
		
		APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	
	}
	
	
	
	/**
	 * 全宗类型统计
	 * @param @param mapping
	 * @param @param form
	 * @param @param request
	 * @param @param response
	 * @date 2018年5月29日
	 * @author zhaoqun
	 */
	public void getQuzongCharts(ActionMapping mapping,ActionForm form, 
			HttpServletRequest request,HttpServletResponse response){
		
		try {
			
			String type =request.getParameter("type");
			
			Map<String,Object> map = this.homePageBO.getQuanzongData(type);
		
		
		APWrite.objectOutJson(map, response);
		} catch (Exception e) {
			try {
				APWrite.outPrintRespose("0", response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	
	}
	
}
